package inherit;

/**
 * Created with IntelliJ IEDA.
 * Description:
 * User:86186
 * Date:2022-05-14
 * Time:14:14
 */
class Base{
    public int a = 1;
    public int b = 2;

    public void methodA(){
        System.out.println("Base中的methodA()");
    }
    public void methodB(){
        System.out.println("Base中的methodB()");
    }
}
class Derived extends Base{
    public int a = 3;
    public int d = 4;

    public void methodA(int a) {
        System.out.println("Derived中的method(int)方法");
    }
    public void methodB(){
        System.out.println("Derived中的methodB()方法");
    }
    public void test(){
        System.out.println(a);
        System.out.println("Base:"+super.a);
        methodA(); // 没有传参，访问父类中的methodA()
        methodA(20); // 传递int参数，访问子类中的methodA(int)
        methodB(); // 直接访问，则永远访问到的都是子类中的methodB()，基类的无法访问到
        super.methodB();
       /* System.out.println(this.a);
        System.out.println(this.b);
        System.out.println(this.d);*/
    }

}

public class Test2 {
    public static void main(String[] args) {
        Derived derived = new Derived();
        derived.test();
    }
}


